package com.fjd.mapper;

import com.fjd.entity.MerchandiseInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface MerchandiseInfoMapper {
    @Select("select * from merchandise_info where merchandise_id =#{id}")
    MerchandiseInfo getById(String id);

    @Select("select * from merchandise_info where merchandise_category = #{category} ")
    List<MerchandiseInfo> getByCategory(String category);

    @Select("select * from merchandise_info where merchandise_name like concat('%',#{record},'%') ")
    List<MerchandiseInfo> getByName(String record);

    List<MerchandiseInfo> getByIds(List<String> ids);

    @Insert("INSERT INTO merchandise_info (merchandise_id, supplier_id, merchandise_name, merchandise_description, merchandise_category, manufacturer, source_of_goods, production_date, shelf_life, temperature_requirement, trace_code, note) VALUES (#{merchandiseId}, #{supplierId}, #{merchandiseName}, #{merchandiseDescription}, #{merchandiseCategory}, #{manufacturer}, #{sourceOfGoods}, #{productionDate}, #{shelfLife}, #{temperatureRequirement}, #{traceCode}, #{note})")
    boolean addMerchandise(MerchandiseInfo merchandiseInfo);

    @Select("select * from merchandise_info")
    List<MerchandiseInfo> getAllMerchandise();

    @Update("UPDATE merchandise_info SET supplier_id = #{supplierId}, merchandise_name = #{merchandiseName}, merchandise_description = #{merchandiseDescription}, merchandise_category = #{merchandiseCategory}, manufacturer = #{manufacturer}, source_of_goods = #{sourceOfGoods}, production_date = #{productionDate}, shelf_life = #{shelfLife}, temperature_requirement = #{temperatureRequirement}, trace_code = #{traceCode}, note = #{note} WHERE merchandise_id = #{merchandiseId}")
    boolean editMerchandise(MerchandiseInfo merchandiseInfo);

    @Insert("INSERT INTO product_images (product_id, image_url, image_index) VALUES (#{procId}, #{imagePath}, #{imageIndex})")
    boolean addMerchandiseImage(String procId, String imagePath, int imageIndex);

}
